<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" href="layui/css/layui.css" media="all">
	</head>
	<body>
		
		<!-- 展示框 -->
		<form class="layui-form">
			<div class="layui-form-item" style="width: 600px;">
			    <input type="hidden" name="medId" id="medId" idautocomplete="off" class="layui-input">
			</div>
		
			<div class="layui-form-item" style="width: 600px;">
			    <label class="layui-form-label">药品名</label>
			    <div class="layui-input-block">
			      <input type="text" name="medName" id="medName" lay-verify="required" autocomplete="off" class="layui-input">
			    </div>
			</div>
			
			<div class="layui-form-item" style="width: 600px;">
			    <label class="layui-form-label">成分</label>
			    <div class="layui-input-block">
			      <input type="text" name="medIngredient" id="medIngredient" lay-verify="required" autocomplete="off" class="layui-input">
			    </div>
			</div>
			
			<div class="layui-form-item" style="width: 600px;">
			    <label class="layui-form-label">性状</label>
			    <div class="layui-input-block">
			      <input type="text" name="medCharacter" id="medCharacter" lay-verify="required" autocomplete="off" class="layui-input">
			    </div>
			</div>
			
			<div class="layui-form-item" style="width: 600px;">
			    <label class="layui-form-label">功效</label>
			    <div class="layui-input-block">
			      <input type="text" name="medEffect" id="medEffect" lay-verify="required" autocomplete="off" class="layui-input">
			    </div>
			</div>
			
			<div class="layui-form-item" style="width: 600px;">
			    <label class="layui-form-label">药品价格</label>
			    <div class="layui-input-block">
			      <input type="text" name="medPrice" id="medPrice" lay-verify="required|number" autocomplete="off" class="layui-input">
			    </div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">库存量</label>
					<div class="layui-input-block">
					  <input type="text" name="medStorage" id="medStorage" lay-verify="required|number" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-inline">
					  <label class="layui-form-label">药厂编号</label>
					  <div class="layui-input-block">
						<input type="text" name="factoryId" id="factoryId" lay-verify="required|number" autocomplete="off" class="layui-input">
					  </div>
				</div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-inline">
					  <label class="layui-form-label">生产日期</label>
					  <div class="layui-input-block">
						<input type="text" name="medProDate" id="date" lay-verify="required|date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
					  </div>
				</div>
				<div class="layui-inline">
					  <label class="layui-form-label">有效期</label>
					  <div class="layui-input-block">
						<input type="text" name="medUseDate" id="date1" lay-verify="required|date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
					  </div>
				</div>
			</div>
			
			<div class="layui-form-item" style="width: 600px;">
			    <div class="layui-input-block" style="text-align:center;">
				  <button class="layui-btn" lay-submit=""  lay-filter="demo2">确定</button>
			      <!-- <button class="layui-btn" lay-submit=""  lay-filter="demo3">删除</button> -->
			    </div>
			</div>
		</form>
		
		<script src="js/jquery-3.4.1.js"></script>
		<script src="layui/layui.js"></script>
		<script>
			layui.use(['form', 'laydate'], function(){
			    var form = layui.form
			    ,layer = layui.layer
				,laydate = layui.laydate
				,$=layui.jquery;
				
				//日期
				laydate.render({
				    elem: '#date'
				});
				laydate.render({
				    elem: '#date1'
				});
				
				//监听提交
				form.on('submit(demo2)', function(data){
				    // layer.alert(JSON.stringify(data.field), {
				    //   title: '最终的提交信息'
				    // })
					$.ajax({
						type:"post",
						url:"http://localhost:8081/admin/updateMedicine",
						async:true,
						contentType:"application/json;charset=UTF-8",
						data:JSON.stringify(data.field),
						xhrFields: {
							withCredentials: true
						},
						success:function(res){
							$('input').val("");
							//sessionStorage.setItem("userName",res.data);
							console.log(res);
							
							if(res.code>=0){
								layer.msg(res.msg,{time: 1000},function () {
									var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
									parent.layer.close(index); //再执行关闭
									parent.tableIn.reload();
								});
							}else{
								layer.msg(res.msg);
							}
							
						}
					});
				    return false;
				});
			});
		</script>
		
	</body>
</html>
